from allpairspy import AllPairs
from api_py.generate_case.template import template_case
from api_py.utils.file_sys import write_json

# TODO 假设已经插入了一个不合法的用户名，应不应该让它登录进去

"""
    username : 字母开头+字母/数字，长度4-24
    password : 密码长度为6-20位数字、字母、下划线组成
"""

username = [
    {"value": "", "description": "用户名为空"},
    {"value": "invalid@user", "description": "用户名存在非法字符"},
    {"value": "kfcvw50", "description": "用户名合法"},
    {"value": "aaa", "description": "用户名长度小于4"},
    {"value": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "description": "用户名长度大于24"},
    {"value": "123username", "description": "用户名以数字开头"},
]

password = [
    {"value": "", "description": "密码为空"},
    {"value": "aaa", "description": "密码长度小于3"},
    {"value": "aaaaaa", "description": "密码合法"},
    {"value": "aaaaaaaaaaaaaaaaaaaaaaaaa", "description": "密码长度大于20"},
    {"value": "aaa非法@@@", "description": "密码存在特殊字符"},
    {"value": "aaaaaaaaaaaaaaaaaaaa", "description": "密码长度恰好为20"}
]


def case01_auth_login(api_type):
    json_result = {}
    parameters = [username, password]

    for i, pairs in enumerate(AllPairs(parameters)):
        case = template_case()
        request = case["request"]

        # 设置请求体参数
        request["body"]["username"] = pairs[0]
        request["body"]["password"] = pairs[1]

        json_result[i] = case
    write_json(api_type.value[0]["file_name"], json_result)
